<!doctype html>
<html class="no-js">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>商之联后台管理系统</title>
  <meta name="description" content="商之联后台管理系统">
  <meta name="keywords" content="form">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <link rel="icon" type="image/png" href="{:C('ADMIN_IMAGE')}favicon.png">
  <link rel="apple-touch-icon-precomposed" href="{:C('ADMIN_IMAGE')}app-icon72x72@2x.png">
  <meta name="apple-mobile-web-app-title" content="Amaze UI" />
  <link rel="stylesheet" href="{:C('ADMIN_CSS')}amazeui.min.css"/>
  <link rel="stylesheet" href="{:C('ADMIN_CSS')}admin.css">
</head>
<body>
<!--[if lte IE 9]>
<p class="browsehappy">你正在使用<strong>过时</strong>的浏览器，Amaze UI 暂不支持。 请 <a href="http://browsehappy.com/" target="_blank">升级浏览器</a>
  以获得更好的体验！</p>
<![endif]-->
<!-- header start-->

<include file="Public:header"/>

<!-- header end-->
<div class="am-cf admin-main">
<!-- sidebar start -->
   <include file="Public:menu"/>
  <!-- sidebar end -->

<!-- content start -->
<form action="{:U('Type/updateType')}" class="am-form am-form-inline" name="type" 
  method="post" enctype="multipart/form-data">
<div class="admin-content">

  <div class="am-cf am-padding">
    <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">类目管理</strong> / <small>编辑类目</small></div>
  </div>

  <div class="am-tabs am-margin" data-am-tabs="{noSwipe: 1}">
    <ul class="am-tabs-nav am-nav am-nav-tabs">
      <li class="am-active"><a href="#tab1">基本信息</a></li>
      <li class=""><a href="#tab2">扩展属性</a></li>
    </ul>
    <div class="am-tabs-bd">
      <div class="am-tab-panel am-fade am-in am-active" id="tab1">
        <div class="am-g am-margin-top">
          <div class="am-u-sm-2 am-text-right">
            类目名称
          </div>
          <div class="am-u-sm-10">          
              <div class="am-form-group am-form-icon">
                <input type="text" name='name' class="am-form-field am-input-sm" value="{$typeinfo['typename']}" onblur="unique()">
              </div>
          </div>
        </div>
        <div class="am-g am-margin-top">
          <div class="am-u-sm-2 am-text-right">
            上级类目
          </div>

          <div class="am-u-sm-10">
              <div class="am-form-group am-form-icon">
                <select  name="typeid" >
                  <option value='0'>请选择</option>
                  <foreach name="tree" item="value">
                    <if condition="$value.pid eq 0 ">
                        <option value="{$value['typeid']}"  <if condition="$typeinfo['pid'] eq $value['typeid'] ">selected=1 </if> >
                          <?php  echo $value['typename'];?>
                        </option>
                    <else/>
                    <option value="{$value['typeid']}"> 
                    <?php  echo str_repeat('&nbsp;&nbsp;&nbsp;',$value['level']).'|_'.$value['typename'];?>
                     </option>
                    </if>
                  </foreach> 
                </select>
              </div>
          </div>
        </div>
         


        <div class="am-g am-margin-top">
          <div class="am-u-sm-2 am-text-right">首页类目图</div>
          <div class="am-u-sm-10">
           <div class="am-form-group">
          <input type="file" id="doc-ipt-file-1" name="listimg">

          <p class="am-form-help">请选择要上传的文件...(顶级类目像素要求80*80,二级类目像素要求557*557)</p>
          <div><if condition="$typeinfo['imgpath'] neq '' ">
          <img src="{:C('SITENAME')}{$typeinfo['imgpath']}">
          </if>
          </div>
       </div>

          </div>
        </div>

      </div>
    <!--扩展属性start-->
    <div class="am-tab-panel am-fade am-in am-active" id="tab2">
    <table class="am-table am-table-bordered am-table-striped am-table-compact" id='proper'>
    <thead>
        <tr>
            <th>属性名</th>
            <th>属性值</th>
            <th>操作</th>
            <th>创建人</th>
        </tr>
    </thead>
    <tbody>
    <foreach name="propertys" item="property">
        <tr class='row'>
            <td>{$property['propertyname']}</td>
            <td>{$property['selval']}</td>
            <td>
            <a href="">
            <button class="am-btn am-btn-default am-btn-xs am-text-danger"
             onclick="ajaxdel({$property['propertyid']})">
            <span class="am-icon-trash-o"></span> 删除</button>
            </a>
            <a href="">
            <button class="am-btn am-btn-default am-btn-xs am-text-secondary doc-prompt-toggle" onclick="prompt({$property['propertyid']})" >
            <span class="am-icon-pencil-square-o">编辑</span></button></a>
            </td>
            <td>Amaze UI</td>
        </tr>
        </foreach>
       <tfoot>
            <tr>
              <td colspan="5">
                <p>
                  <button class="am-btn am-btn-default am-btn-xs am-text-secondary"  onclick="addproper()">
            <span class="am-icon-pencil-square-o"></span>添加更多</button>
                </p>
              </td>
            </tr>
          </tfoot>
    </tbody>
    </table>
    </div>
    <!--扩展属性end-->
    </div>


  </div>

  <div class="am-margin">

     <input type="submit" class="am-btn am-btn-primary am-btn-xs"  value="提交保存">
    <button type="reset" class="am-btn am-btn-primary am-btn-xs">重置</button>
  </div>
</div>
<input type='hidden'   name='tid' class="tid" value="{$typeid}">
</form>
<!-- content end -->
</div>

<script src="{:C('ADMIN_JS')}jquery.min.js"></script>
<include file="Public:footer"/>

<!--[if lt IE 9]>
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="{:C('SUPPLIER_ADMIN_JS')}polyfill/rem.min.js"></script>
<script src="{:C('SUPPLIER_ADMIN_JS')}polyfill/respond.min.js"></script>
<script src="{:C('SUPPLIER_ADMIN_JS')}amazeui.legacy.js"></script>
<![endif]-->

<!--[if (gte IE 9)|!(IE)]><!-->

<script src="{:C('ADMIN_JS')}amazeui.min.js"></script>
<!--<![endif]-->
<script src="{:C('SUPPLIER_ADMIN_JS')}app.js"></script>
<script type="text/javascript">
 function addproper(){
   $('#proper').append("<tr class='row'><td><input type='text' name='propertynames[]' class='am-form-field am-input-sm' placeholder='请填写'></td><td><input type='text' name='selvals[]' class='am-form-field am-input-sm' placeholder='多个属性值，用中文逗号（,）分隔'></td> <td><button class='am-btn am-btn-default am-btn-xs am-text-danger' onclick=delnewrow(this) ><span class='am-icon-trash-o'></span> 删除</button></td><td>Amaze UI</td></tr>");
   event.preventDefault();
   return false;
 }
  //删除追的的属性名及值
function delnewrow(e){
  event.preventDefault();
  $child=$(e);
  $child.parent().parent().remove();
}
</script>
<script type="text/javascript">
 function ajaxdel(propertyid){
    var res=confirm('删除此属性前，请核对此属性是否被其他商品使用');

    if(res==false){
      event.preventDefault(); 
      return false;
    }
    var proid=propertyid;
   
   $.ajax({
      type:'POST',
      url:"{:U('Type/ajaxDelpro')}",
      data:{'propertyid':proid},
      dataType:"text",
      success:function(data)
      {
          if(data==1){
            alert('删除成功');
             location.reload();
          } if(data==2){
            alert('请先删除该属性下的商品');
          }
      }
      }
      );
   event.preventDefault(); 
  }
</script>
<script type="text/javascript">
  //编辑扩展属性
  function prompt(propertyid){
     var proid=propertyid;
     $.ajax({
      type:'POST',
      url:"{:U('Type/ajaxProval')}",
      data:{'propertyid':proid},
      dataType:"json",
      success:function(result)
      {
          if(result.error==0){ 
            //加载弹出层
            $('#propertyname').val(result.propertyname);
            $('.hiddpropid').val(proid);
            $.each(result.proval,function(k,v){
$('#editpro').append("<tr class='editrow'><td><input type='text' name='proval[]["+k+"]' class='am-form-field am-input-sm' value="+v+"></td> <td><button class='am-btn am-btn-default am-btn-xs am-text-danger' id='sc'><span class='am-icon-trash-o'></span><a href='javascript:del("+k+");'>删除</a></button></td></tr>");
            });
            
            $('#my-prompt').modal
           ({
                relatedTarget: this,
                 onConfirm:function(e){
                   $('#propertyform').submit()
                 },
                 onCancel: function(e) 
                 {
                    $('.editrow').remove();
                 }
                 
           }
           );  


          }else if(data.error==1){
           

          }
      }

      });
      event.preventDefault();
  }
//添加更多属性值
  function addspecval(){
    event.preventDefault();
    $('#editpro').append("<tr class='newrow'><td><input type='text' name='addval[]' class='am-form-field am-input-sm' ></td> <td><button class='am-btn am-btn-default am-btn-xs am-text-danger' onclick='delpro(this);return false'><span class='am-icon-trash-o'></span> <a hefe='javascript:void(0)'>删除</a></button></td></tr>");
  }; 
  //删除追加的属性
  function delpro(e){
    event.preventDefault();
  $child=$(e);
  $child.parent().parent().remove();
  }
  //ajax 删除属性
 function del(propertyid){
    var res=confirm('删除此属性前，请核对此属性是否被其他商品使用');

    if(res==false){
      event.preventDefault(); 
      return false;
    }
    var proid=propertyid;
   
   $.ajax({
      type:'POST',
      url:"{:U('Type/Delpro')}",
      data:{'valueid':proid},
      dataType:"text",
      success:function(data)
      {
          if(data==1){
            alert('删除成功');
             location.reload();
          } if(data==2){
            alert('请先删除该属性下的商品');
          }
      }
      }
      );
    
  }
</script>
<script type="text/javascript">
  
function unique(){
  typename=$("input[name='name']").val();

 jQuery.get('{:U("Type/ajaxtype")}',
  {name:typename,},
  function(data){
  if(data.status===404){
    alert(data.info);
    $("input[name='name']").val("");
     event.preventDefault();
 

  }
 },'json');
 
}

</script>
<!--编辑扩展属性弹出层 -->
<div class="am-modal am-modal-prompt" tabindex="-1" id="my-prompt" style="margin-top:-356px;height:600px;overflow: scroll;background-color:#fff">
<form action="{:U('Type/updateProper')}" method='post' id="propertyform">
  <div class="am-modal-dialog">
    <div class="am-modal-hd">编辑属性</div>
    <div class="am-modal-bd">

        <div class="am-g am-margin-top">
          <div class="am-u-sm-2 am-text-right" >
            属性名
          </div>
          <div class="am-u-sm-10">
            
              <div class="am-form-group am-form-icon">
                <input type="text" name="name" class="am-form-field am-input-sm" id='propertyname' >
              </div>
          </div>

        </div>

        <div class="am-g am-margin-top">
          <div class="am-u-sm-12">
            <table class="am-table am-table-bordered am-table-striped am-table-compact" id='editpro'>
    <thead>
        <tr>
            <th>属性值</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
      </tbody>
</table>
      <button class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="addspecval()">
      <span class="am-icon-pencil-square-o"></span>添加更多</button>
 <input type='hidden'  class="hiddpropid" name='hiddpropid'>
 </div>
</div>
    </div>
    <div class="am-modal-footer">
      <span class="am-modal-btn" data-am-modal-cancel>取消</span>
      <span class="am-modal-btn" data-am-modal-confirm>提交</span>
      
    </div>
  </div>
  </form>
</div>
</body>
</html>
